package com.study.kafka.custom.serialization;

import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import org.apache.kafka.common.serialization.Deserializer;

import java.util.Map;

/**
 * 自定义反序列化，使用protostuff实现
 *
 * @author: stephen.shen
 * @create: 2019-06-18 11:06
 */
public class DemoDeserializer implements Deserializer<Person> {

    @Override
    public void configure(Map configs, boolean isKey) {

    }

    @Override
    public Person deserialize(String topic, byte[] data) {
        if (data == null) {
            return null;
        }
        Schema<Person> schema = RuntimeSchema.getSchema(Person.class);
        Person person = new Person();
        ProtostuffIOUtil.mergeFrom(data, person, schema);

        return person;
    }

    @Override
    public void close() {

    }
}
